# 买卖股票的最佳时机

class Solution(object):
    def maxProfit(self, prices):
        """
        :type prices: List[int]
        :rtype: int
        """
        if len(prices) <= 1:
            return 0
        result = list()

        for i in range(len(prices)-1):
            result.append(max(prices[i+1:]) - prices[i])

        return max(result) if max(result) > 0 else 0


class Solution(object):
    def maxProfit(self, prices):
        """
        :type prices: List[int]
        :rtype: int
        """
        if len(prices) <= 1:
            return 0

        inf = int(1e9)
        minprice = inf  # 用于记录历史最低点
        maxprice = 0  # 用于记录最大利润

        for price in prices:
            maxprice = max(price - minprice, maxprice)
            minprice = min(price, minprice)

        return maxprice
